﻿using System.Collections.Generic;

namespace DM4
{
    public static class MailSenderConsts
    {
        public const string ModuleCode = "DMN_MAILSENDER";
        public const string IdFormat = "yyyy MMM dd HH:mm:ss ffff";
        public const int Timeout = 5000;
    }

    public static class MailListenerConsts
    {
        public const string ModuleCode = "DMN_MAILLISTENER";
        public const string IdFormat = "yyyy MMM dd HH:mm:ss ffff";
        public const int Timeout = 5000;
    }

    public static class MailSenderCommands
    {
        public const string SendMail = "SEND MAIL";
    }

    public static class MailListenerCommands
    {
        public const string CheckMail = "CHECK MAIL";
    }

    public class MailListenerParameters
    {
        public int MailAccountIdForCheck = DM4Consts.DefaultNULLId;
        public List<int> LetterIds = new List<int>();
        public int Timeout = MailListenerConsts.Timeout;
        public int Attempts = 1;
    }

    public class MailSenderParameters
    {
        private readonly int _accFromId = DM4Consts.DefaultNULLId;
        private readonly string _accountFrom = "";
        private readonly string _mailTo = "";
        private readonly int _mailTemplateId = DM4Consts.DefaultNULLId;
        private readonly string _mailTemplateName = "";
        private readonly string _body = "";
        private readonly string _subject = "";
        private readonly Dictionary<string, string> _macros = new Dictionary<string, string>();
        private readonly int _attempts = 1;
        private readonly int _timeout = MailSenderConsts.Timeout;

        public int AccFromId { get { return _accFromId; } }
        public string AccFrom { get { return _accountFrom; } }
        public string MailTo { get { return _mailTo; } }
        public int MailTemplateId { get { return _mailTemplateId; } }
        public string MailTemplateName { get { return _mailTemplateName; } }
        public string Body { get { return _body; } }
        public string Subject { get { return _subject; } }
        public Dictionary<string, string> Macros { get { return _macros; } }
        public int Attempts { get { return _attempts; } }
        public int Timeout { get { return _timeout; } }

        public MailSenderParameters(int accountFromId, string mailTo, int mailTemplateId, Dictionary<string, string> macros, int attempts = 1, int timeout = MailSenderConsts.Timeout)
        {
            _accFromId = accountFromId;
            _mailTo = mailTo;
            _mailTemplateId = mailTemplateId;
            _macros = macros;
            _attempts = attempts;
            _timeout = timeout;
        }

        public MailSenderParameters(string accountFrom, string mailTo, string mailTemplateName, Dictionary<string, string> macros, int attempts = 1, int timeout = MailSenderConsts.Timeout)
        {
            _accountFrom = accountFrom;
            _mailTo = mailTo;
            _mailTemplateName = mailTemplateName;
            _macros = macros;
            _attempts = attempts;
            _timeout = timeout;
        }

        public MailSenderParameters(string accountFrom, string mailTo, string body, string subject, int attempts = 1, int timeout = MailSenderConsts.Timeout)
        {
            _accountFrom = accountFrom;
            _mailTo = mailTo;
            _body = body;
            _subject = subject;
            _attempts = attempts;
            _timeout = timeout;
        }

        public MailSenderParameters(int accountFromId, string mailTo, string body, string subject, int attempts = 1, int timeout = MailSenderConsts.Timeout)
        {
            _accFromId = accountFromId;
            _mailTo = mailTo;
            _body = body;
            _subject = subject;
            _attempts = attempts;
            _timeout = timeout;
        }
    }



}
